﻿using BaoVeThanhDia.Buttons;
using BaoVeThanhDia.GamePlay.Towers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;

namespace BaoVeThanhDia.Introduction
{
    class TowerInfo
    {
        int TypeThap;// loại lính(basic,bow,cannon,magic,soul
        int LevelTower;// level 1,2,3,4
        int TypeTower; //loại tháp 0,1,2
        List<Button> buttons;
        Tower ImageTower;
        Vector2 Position;
        float scale;
        bool isTouched;
        public TowerInfo(int typeThap, int level, int type)
        {
            this.TypeThap = typeThap;
            this.LevelTower = level;
            this.TypeTower = type;
            buttons = new List<Button>();
            setPosition();
            buttons.Add(new Button("border", "images/Introduction/border", Position, Vector2.Zero, new Vector2(45, 45), 1.1f));
            if (TypeThap == 0)
            {
                ImageTower = new BasicTower(Vector2.Zero, level, type);
            }
            else if (TypeThap == 1)
            {
                ImageTower = new BowTower(Vector2.Zero, level, type);
            }
            else if (TypeThap == 2)
            {
                ImageTower = new CannonTower(Vector2.Zero, level, type);
            }
            else if (TypeThap == 3)
            {
                ImageTower = new MagicTower(Vector2.Zero, level, type);
            }
            else
            {
                ImageTower = new SoulTower(Vector2.Zero, level, type);
            }
            scale = 0.4f;
        }
        public void Load(ContentManager cont)
        {
            foreach (Button button in buttons)
            {
                button.Load(cont);
            }
            ImageTower.Load(cont);
        }
        public void Draw(SpriteBatch sprite, Vector2 Dolech)
        {
            foreach (Button button in buttons)
            {
                button.Draw(sprite, Dolech);
            }
            ImageTower.OptionDraw(sprite, Position + new Vector2(5, 0), Dolech, scale, isTouched);
        }
        public bool isTouch(Vector2 touch, Vector2 Dolech)
        {
            isTouched = false;
            touch -= Dolech;
            if (buttons[0].isTouch(touch))
            {
                buttons[0].setTouch(false);
                isTouched = true;
                return true;
            }
            return false;
        }
        public int getTypeThap() { return TypeThap; }
        public int getLevel() { return LevelTower; }
        public int getTypeTower() { return TypeTower; }
        private void setPosition()
        {
            switch (TypeThap)
            {
                case 0:
                    #region tháp cơ bản
                    if (LevelTower == 1) Position = new Vector2(102, 110);
                    else Position = new Vector2(-17 + TypeTower * 80, 30 + LevelTower * 70);
                    break;
                    #endregion
                default:
                    {
                        Position.Y = -10 + LevelTower * 61;
                        Position.X = (TypeTower == 1 ? 60 : (TypeTower == 0 ? 100 : 140)) + 200 * TypeThap;
                        break;
                    }
            }
        }
    }
}
